import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Work {

    public static final String[] suits={"♥","♠","♦","♣"};
    //产生一副52张牌
    public List<Card> buyCard(){
        List<Card> cardlist=new ArrayList<>();
        for (int i = 1; i <=13; i++) {

            for (int j =0; j <4; j++) {
                int num=i;
                String suit=suits[j];
                Card card=new Card(num,suit);
                cardlist.add(card);

            }
        }
        return cardlist;
    }
    //打乱牌的顺序
    public void shuffle(List<Card> cardlist){
        Random random=new Random();
        for(int i=cardlist.size()-1;i>0;i--){
            int index=random.nextInt(i);
            swap(cardlist,i,index);
        }
    }
    //交换牌的顺序
    public void swap(List<Card> cardlist,int i,int j){
        Card tmp=cardlist.get(i);
        cardlist.set(i,cardlist.get(j));
        cardlist.set(j,tmp);
    }
    //玩牌，三个人每人顺着拿一张，一人拿五张
    public List<List<Card>> playCard(List<Card> cardlist){
        List<Card> hand0=new ArrayList<>();
        List<Card> hand1=new ArrayList<>();
        List<Card> hand2=new ArrayList<>();

        List<List<Card>> hand=new ArrayList<>();
        hand.add(hand0);
        hand.add(hand1);
        hand.add(hand2);
        for (int i = 0; i <5; i++) {
            for (int j = 0; j <3; j++) {
                Card card=cardlist.remove(0);
                hand.get(j).add(card);
            }
        }
        return hand;
    }
}
